Page({
  data: {
    shareInfo: {
      title: '朋友圈分享', // 分享标题
      desc: '欢迎大家使用', // 分享描述
      link: '', // 分享链接
      imgUrl: '', // 分享图片链接
    },
  },
  onLoad: function() {
    // 设置分享配置信息
    this.setData({
      shareInfo: {
        title: '朋友圈分享',
        desc: '欢迎大家使用',
        link: '',
        imgUrl: '',
      },
    });
  },
  // 分享到微信好友
  shareToWeixin: function() {
    wx.shareAppMessage({
      title: this.data.shareInfo.title,
      desc: this.data.shareInfo.desc,
      link: this.data.shareInfo.link,
      imgUrl: this.data.shareInfo.imgUrl,
      success: function(res) {
        console.log('分享成功', res);
      },
      fail: function(res) {
        console.log('分享失败', res);
      },
    });
  },
  // 分享到微信朋友圈
  shareToTimeline: function() {
    wx.shareTimeline({
      title: this.data.shareInfo.title,
      desc: this.data.shareInfo.desc,
      link: this.data.shareInfo.link,
      imgUrl: this.data.shareInfo.imgUrl,
      success: function(res) {
        console.log('分享成功', res);
      },
      fail: function(res) {
        console.log('分享失败', res);
      },
    });
  },
  // 分享到QQ
  shareToQQ: function() {
    wx.shareQQ({
      title: this.data.shareInfo.title,
      desc: this.data.shareInfo.desc,
      link: this.data.shareInfo.link,
      imgUrl: this.data.shareInfo.imgUrl,
      success: function(res) {
        console.log('分享成功', res);
      },
      fail: function(res) {
        console.log('分享失败', res);
      },
    });
  },
  // 分享到其他平台（例如微博、钉钉等）
  shareToOtherPlatform: function(e) {
    const platform = e.currentTarget.dataset.type;
    wx.share({
      title: this.data.shareInfo.title,
      desc: this.data.shareInfo.desc,
      link: this.data.shareInfo.link,
      imgUrl: this.data.shareInfo.imgUrl,
      success: function(res) {
        console.log('分享成功', res);
      },
      fail: function(res) {
        console.log('分享失败', res);
      },
    });
  },
});
